<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" placeholder="排序号"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="申请人员" prop="userId">
						<select-hr-user-dialog v-model:userId="form.userId" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="职称获取类型" prop="getType">
						<sc-select v-model="form.getType" :params="{code:'getType'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			<el-col :lg="12">
				<el-form-item label="申报称职名称" prop="postName">
					<el-input v-model="form.postName" placeholder="申报称职名称"></el-input>
				</el-form-item>
			</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="职称申请日期" prop="applyTime">
						<el-date-picker v-model="form.applyTime" placeholder="职称申请日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="职称获取日期" prop="receiveTime">
						<el-date-picker v-model="form.receiveTime" placeholder="职称获取日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="下次申报日期" prop="nextApplyTime">
						<el-date-picker v-model="form.nextApplyTime" placeholder="下次申报日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="下次申报资称" prop="nextPostName">
						<el-input v-model="form.nextPostName" placeholder="下次申报资称"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="聘用公司" prop="employComp">
						<el-input v-model="form.employComp" placeholder="聘用公司" maxlength="50"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="聘用职务" prop="employPost">
						<el-input v-model="form.employPost" placeholder="聘用职务" maxlength="50"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="聘用开始日期" prop="employBeginTime">
						<el-date-picker v-model="form.employBeginTime" placeholder="聘用开始日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="聘用结束日期" prop="employEndTime">
						<el-date-picker v-model="form.employEndTime" placeholder="聘用结束日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="评定备注">
				<el-input v-model="form.remark" placeholder="评定备注" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
			<el-form-item label="相关附件" prop="attachId">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'hr'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectHrUserDialog from "@/views/module/selectHrUserDialog";
import AttachMenu from '@/views/module/attachMenu'
export default {
	emits: ['success', 'closed'],
	components: {
		selectHrUserDialog,AttachMenu
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			btName: "保存",
			titleMap: {
				add: '添加评定记录',
				edit: '编辑评定记录',
				show: '查看'
			},
			fileList: [],
			apiObj: this.$API.file.attach.uploadFile,
			templateList: [],
			templates: [],
			form: {
				recordId: '',
				sortNo: '',
				getType: '',
				userId: '',
				postName:'',
				applyTime: '',
				receiveTime: '',
				nextApplyTime: "",
				nextPostName:'',
				employComp:'',
				employPost:'',
				employBeginTime:'',
				employEndTime:'',
				attachId: '',
				remark: ''
			},
			rules: {
				userId: [
					{required: true, message: '关联人不能为空', trigger: 'change'}
				],
				getType: [
					{required: true, message: '职称获取类型不能为空'}
				],
				applyTime: [
					{required: true, message: '申请日期不能为空'}
				],
				employComp: [
					{required: true, message: '聘用公司不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.hr.hrTitleEvaluation.insertHrTitleEvaluation.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.hr.hrTitleEvaluation.updateHrTitleEvaluation.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.sortNo = data.sortNo
			this.form.userId = data.userId
			this.form.getType = data.getType
			this.form.postName = data.postName
			this.form.applyTime = data.applyTime
			this.form.receiveTime = data.receiveTime
			this.form.nextApplyTime = data.nextApplyTime
			this.form.nextPostName = data.nextPostName
			this.form.employComp = data.employComp
			this.form.employPost = data.employPost
			this.form.employBeginTime = data.employBeginTime
			this.form.employEndTime = data.employEndTime
			this.form.attachId = data.attachId
			this.form.remark = data.remark
		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
